﻿using System;
using System.Collections.Generic;
using Ext.Net;
using BLL;
using Model;
using System.Xml;
using System.Xml.Xsl;

namespace Web.View.d50_qtxxMenu
{
    public partial class Default : UIPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        //绑定Grid
        protected void d50_qtxx_DataBind(object sender, StoreRefreshDataEventArgs e)
        {
            d50_qtxxMgr mgr = new d50_qtxxMgr();
            e.Total = int.Parse(mgr.GetRecordCount_d50_qtxx(e.Parameters[d50_qtxx_Filter.ParamPrefix]));
            IList<d50_qtxx> list = mgr.FindAllByPage_d50_qtxx(e.Start.ToString(), e.Limit.ToString(), e.Parameters[d50_qtxx_Filter.ParamPrefix]);
            d50_qtxx_MainStore.DataSource = list;
            d50_qtxx_MainStore.DataBind();
        }
        //删除数据
        protected void BtnDel_Click(object sender, DirectEventArgs e)
        {
            d50_qtxxMgr mgr = new d50_qtxxMgr();
            RowSelectionModel sm = d50_qtxx_Grid.SelectionModel.Primary as RowSelectionModel;
            foreach (SelectedRow row in sm.SelectedRows)
            {
                d50_qtxx _d50_qtxx = new d50_qtxx();
                _d50_qtxx.zyid = row.RecordID;//int.Parse(row.RecordID);
                if (mgr.Del_d50_qtxx(_d50_qtxx))
                {
                    log.Debug("d50_qtxx中执行了删除，并成功");
                    X.Msg.Notify("成功", "<font color='green'>已经成功删除选中的记录</font>").Show();
                }
                else
                    X.Msg.Notify("失败", "<font color='green'>删除记录失败，请您重试！</font>").Show();
            }
            d50_qtxx_Grid.Reload();
        }
        protected void BtnSave_Click(object sender, DirectEventArgs e)
        {
            d50_qtxxMgr mgr = new d50_qtxxMgr();
            d50_qtxx _d50_qtxx = new d50_qtxx();
            if (Hid.Text.Length > 0)
                _d50_qtxx = mgr.FindById_d50_qtxx(int.Parse(Hid.Text));
            
			_d50_qtxx.zybh = Txtzybh.Text.Trim();
			_d50_qtxx.mzbh = Txtmzbh.Text.Trim();
			_d50_qtxx.zycs = int.Parse(TxtNumzycs.Text.Trim());
			_d50_qtxx.dqbm = Txtdqbm.Text.Trim();
			_d50_qtxx.hbh = Txthbh.Text.Trim();
			_d50_qtxx.grbm = Txtgrbm.Text.Trim();
			_d50_qtxx.grade = Txtgrade.Text.Trim();
			_d50_qtxx.rbh = Txtrbh.Text.Trim();
			_d50_qtxx.dzbm = Txtdzbm.Text.Trim();
			_d50_qtxx.zbh = Txtzbh.Text.Trim();
			_d50_qtxx.cbh = Txtcbh.Text.Trim();
			_d50_qtxx.zen = Txtzen.Text.Trim();
			_d50_qtxx.cun = Txtcun.Text.Trim();
			_d50_qtxx.gldm = Txtgldm.Text.Trim();
			_d50_qtxx.jgdm = Txtjgdm.Text.Trim();
			_d50_qtxx.jgmc = Txtjgmc.Text.Trim();
			_d50_qtxx.usid = Txtusid.Text.Trim();
			_d50_qtxx.brlxid = Txtbrlxid.Text.Trim();
			_d50_qtxx.gfbh = Txtgfbh.Text.Trim();
			_d50_qtxx.brxm = Txtbrxm.Text.Trim();
			_d50_qtxx.xbid = Txtxbid.Text.Trim();
			_d50_qtxx.brnl = Txtbrnl.Text.Trim();
			_d50_qtxx.hzgx = Txthzgx.Text.Trim();
			_d50_qtxx.csrq = Txtcsrq.Text.Trim();
			_d50_qtxx.yebz = Txtyebz.Text.Trim();
			_d50_qtxx.hyzkmc = Txthyzkmc.Text.Trim();
			_d50_qtxx.hyid = Txthyid.Text.Trim();
			_d50_qtxx.csddmc = Txtcsddmc.Text.Trim();
			_d50_qtxx.mzmc = Txtmzmc.Text.Trim();
			_d50_qtxx.gjid = Txtgjid.Text.Trim();
			_d50_qtxx.sfzh = Txtsfzh.Text.Trim();
			_d50_qtxx.gzdw = Txtgzdw.Text.Trim();
			_d50_qtxx.dwdh = Txtdwdh.Text.Trim();
			_d50_qtxx.dwyb = Txtdwyb.Text.Trim();
			_d50_qtxx.hkdz = Txthkdz.Text.Trim();
			_d50_qtxx.hkyb = Txthkyb.Text.Trim();
			_d50_qtxx.lxrm = Txtlxrm.Text.Trim();
			_d50_qtxx.gxid = Txtgxid.Text.Trim();
			_d50_qtxx.lxdz = Txtlxdz.Text.Trim();
			_d50_qtxx.lxdh = Txtlxdh.Text.Trim();
			_d50_qtxx.ryksid = Txtryksid.Text.Trim();
			_d50_qtxx.ryksmc = Txtryksmc.Text.Trim();
			_d50_qtxx.rybs = Txtrybs.Text.Trim();
			_d50_qtxx.rycw = Txtrycw.Text.Trim();
			_d50_qtxx.rysj = Txtrysj.Text.Trim();
			_d50_qtxx.rybqid = Txtrybqid.Text.Trim();
			_d50_qtxx.zkbqid = Txtzkbqid.Text.Trim();
			_d50_qtxx.cyksid = Txtcyksid.Text.Trim();
			_d50_qtxx.cyksmc = Txtcyksmc.Text.Trim();
			_d50_qtxx.cybs = Txtcybs.Text.Trim();
			_d50_qtxx.cycw = Txtcycw.Text.Trim();
			_d50_qtxx.cysj = Txtcysj.Text.Trim();
			_d50_qtxx.zyts = int.Parse(TxtNumzyts.Text.Trim());
			_d50_qtxx.mzzd = Txtmzzd.Text.Trim();
			_d50_qtxx.ryzd = Txtryzd.Text.Trim();
			_d50_qtxx.zdmc = Txtzdmc.Text.Trim();
			_d50_qtxx.ryqzsj = Txtryqzsj.Text.Trim();
			_d50_qtxx.zyzt = Txtzyzt.Text.Trim();
			_d50_qtxx.yzxs = Txtyzxs.Text.Trim();
			_d50_qtxx.yzzj = Txtyzzj.Text.Trim();
			_d50_qtxx.qfje = Txtqfje.Text.Trim();
			_d50_qtxx.fdje = Txtfdje.Text.Trim();
			_d50_qtxx.bsbl = Txtbsbl.Text.Trim();
			_d50_qtxx.hjje = Txthjje.Text.Trim();
			_d50_qtxx.kbje = Txtkbje.Text.Trim();
			_d50_qtxx.mxhj = Txtmxhj.Text.Trim();
			_d50_qtxx.etys = Txtetys.Text.Trim();
			_d50_qtxx.mzys = Txtmzys.Text.Trim();
			_d50_qtxx.hlzt = Txthlzt.Text.Trim();
			_d50_qtxx.cwbz = Txtcwbz.Text.Trim();
			_d50_qtxx.qfjsbz = Txtqfjsbz.Text.Trim();
			_d50_qtxx.qfjsje1 = Txtqfjsje1.Text.Trim();
			_d50_qtxx.qfjsje = Txtqfjsje.Text.Trim();
			_d50_qtxx.jssj = Txtjssj.Text.Trim();
			_d50_qtxx.lsh = Txtlsh.Text.Trim();
			_d50_qtxx.hsx = Txthsx.Text.Trim();
			_d50_qtxx.chsx = Txtchsx.Text.Trim();

            bool isok = false;
            if (Hid.Text.Length > 0)
                isok = mgr.Update_d50_qtxx(_d50_qtxx);
            else
                isok = mgr.Add_d50_qtxx(_d50_qtxx);
            if (isok)
            {
                d50_qtxx_Win.Hide();
                X.Msg.Notify("成功", "<font color='green'>恭喜您，操作成功！</font>").Show();
                log.Debug("d50_qtxx中执行了保存（插入或修改），并成功");
                d50_qtxx_Grid.Reload();
            }
            else
                X.Msg.Notify("失败", "<font color='red'>操作失败，请您重试！</font>").Show();
        }
        //数据保存为Excel
        protected void BtnSaveToExcel(object sender, EventArgs e)
        {
            string json = ExcelGridData.Value.ToString();
            StoreSubmitDataEventArgs eSubmit = new StoreSubmitDataEventArgs(json, null);
            XmlNode xml = eSubmit.Xml;
            this.Response.Clear();
            this.Response.ContentType = "application/vnd.ms-excel";
            this.Response.AddHeader("Content-Disposition", "attachment; filename=QiDian10Excel.xls");
            XslCompiledTransform xtExcel = new XslCompiledTransform();
            xtExcel.Load(Server.MapPath("/View/ExcelTemp/Excel.xsl"));
            xtExcel.Transform(xml, null, this.Response.OutputStream);
            this.Response.End();

        }
    }
}